package com.example.commons.entity;

import com.alibaba.fastjson.JSONObject;
import com.example.commons.config.SimpleGrantedAuthorityWrapper;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * spring security用到的实体类
 */
@Data
public class Users implements UserDetails {

    private static final long serialVersionUid = 1L;

    private String id;
    private String username;
    private String password;
    //权限列表
    private List<SimpleGrantedAuthorityWrapper> authorities;
    private String roleKey;
    private String menuKey;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    public void setAuthorities(List<SimpleGrantedAuthorityWrapper> authorities) {
        this.authorities = authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public String toString() {
        return JSONObject.toJSONString(this);
    }
}
